# 1.导包
import pymysql

try:
    # 2. 连接MySQL数据库服务
    connc = pymysql.Connect(
        host='localhost',
        user='root',
        password='123456',
        database='person',
        port=3306,
        charset='utf8'
    )

# 3. 创建游标对象
    cur = connc.cursor()
# 4. 编写sql语句
    # sql = 'select * from 四级单词day1;'
    sql = 'update  四级单词day1 set 词性=%s where id=19 ; '
    update_data = ['n']

# 5. 使用游标对象调用sql

    cur.execute(sql, update_data)

# 提交操作

    connc.commit()
# 6. 查询结果
    result = cur.fetchall()
    print(result)

except Exception as e:
    print(e)
    connc.rollback()
finally:
    # 7. 关闭游标对象

    cur.close()

    # 8. 关闭连接
    connc.close()
print('搞完收工')
